{% extends 'myadmin/public/base.html' %}

{% block title %}
<title>商品分类列表</title>
{% endblock %}

{% block con %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">商品分类列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                </div>
                            </div>
                        </div>
                    </div>
                <form action="" method="get">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select name="types" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                                <option {% if request.GET.types == 'all' %} selected {% endif %} value="all">全局搜索</option>
                              <option {% if request.GET.types == 'name' %} selected {% endif %} value="name">名称</option>
                              <option {% if request.GET.types == 'path' %} selected {% endif %} value="path">path路径</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input value="{{ request.GET.keywords }}" name="keywords" type="text" class="am-form-field ">
                            <span class="am-input-group-btn">
                              <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
                            </span>
                        </div>
                    </div>
                </form>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>订单号</th>
                                    <th>收件人</th>
                                    <th>收件人地址</th>
                                    <th>收件人电话</th>
                                    <th>订单总价</th>
                                </tr>
                            </thead>
                            <tbody>
                              {% for v in ob %}
                                <tr>
                                    <td class="am-text-middle typeid">{{ v.username }}</td>
                                    <td class="am-text-middle">
                                        {% if v.pid != 0 %}
                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                        {% endif %}

                                        <span class="name">{{ v.name }}</span>

                                    </td>

                                    {% if v.father == '顶级' %}
                                     <td class="am-text-middle">{{ v.father }}</td>
                                    {% else %}
                                    <td class="am-text-middle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ v.father }}</td>
                                    {% endif %}

                                    <td class="am-text-middle">{{ v.path }}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="javascript:void(0)"  class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                              {% endfor %}
                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">

                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                <!-- <li class="am-disabled"><a href="#">«</a></li> -->
                                <!-- <li class="am-active"><a href="#">1</a></li> -->
{#                                {% load pagetag_types %}#}
{#                                {% showpage users.paginator.num_pages request %}#}
                                <!-- <li><a  href="#">»</a></li> -->
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">

    {#修改元素#}
    // 找到name元素,绑定双击事件
    $('table .name').dblclick(function(){
        // 获取当前元素的值,现有的类名
        var yname = $(this).text()
        var id = $(this).parents('tr').find('.typeid').text()
        // 创建以 input 放置到 当前元素的位置
        var inp = $('<input type="text" value="'+yname+'" style="color:black;">')
        // 把input加入到当前元素的位置
        $(this).html(inp)
        inp.select()
        var span = $(this)

        // 给input绑定丧失焦点事件
        inp.blur(function(){
            // 获取当前input中的值
            var newname = $(this).val()
            // 判断当前的name是否修改
            if(yname == newname){
                // 没有修改
                span.html(yname)
            }else{
                // 更新 发送ajax请求,更新数据
                $.get('{% url "myadmin_types_update" %}',{'id':id,'name':newname},function(data){
                    if(data.error == 0){
                        // 成功
                        span.html(newname)
                    }
                    alert(data.msg)
                },'json')

            }
        })
    })






    // 获取删除按钮,绑定单击事件
    $('.tpl-table-black-operation-del').click(function(){
        // 获取当前的id号
        var id = $(this).parents('tr').find('.typeid').text()
        var d = $(this)

        // 发送ajax请求,传递id
        $.get('{% url "myadmin_types_delete" %}',{'id':id},function(data){
            if(data.error == 0){
                // 删除成功,删除当前的元素
                // $(this).parents('tr').remove() #XXXXXXX
                // 在此处 $(this) 代表的是 ajax对象 XMLHttpRequest对象
                d.parents('tr').remove()
            }
            alert(data.msg)
        },'json')
    })
</script>

{% endblock %}